package com.zjitc.serviceedu.controller;


import com.zjitc.common.utils.RespBean;
import com.zjitc.serviceedu.entity.EduSubject;
import com.zjitc.serviceedu.entity.subject.OneSubject;
import com.zjitc.serviceedu.entity.subject.TwoSubject;
import com.zjitc.serviceedu.service.EduSubjectService;
import com.zjitc.serviceedu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 赵诚挚
 * @since 2024-09-20
 */
@RestController
@RequestMapping("/serviceedu/edu-subject")
@Api(tags = "课程分类")
public class EduSubjectController {
    @InitBinder
    public void init(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    }
    @Autowired
    private EduSubjectService subjectService;
    //添加课程分类
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubjectExcel")
    public RespBean addSubject(MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        //返回错误提示信息
        subjectService.saveSubject(file,subjectService);
        //判断返回集合是否为空
        return RespBean.success().msg("添加成功");
    }
    //1.根据返回数据创建相应的实体类
    //2.两个实体类表示他们的关系
    @ApiOperation("课程分类列表（树形结构）")
    @GetMapping("getAllSubject")
    public RespBean getAllSubject(){
      List<OneSubject> list = subjectService.getAllOneAndTwoSubject();
        return RespBean.success().data("list",list).msg("查询成功");
    }

    @ApiOperation("根据一级分类ID查询二级分类列表")
    @GetMapping("getTwoSubjectsByParentId/{parentId}")
    public RespBean getTwoSubjectsByParentId(@PathVariable Long parentId) {
        List<TwoSubject> list = subjectService.getTwoSubjectsByParentId(parentId);
        return RespBean.success().data("list", list).msg("查询成功");
    }

}

